/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the implementation of the Chatroom class.
 * This class serves as a container for all chat room information
 * held by the server. */

#include "chatroom.h"

Chatroom::Chatroom(const string& name, const string& password, const ClientEntry& init, unsigned int numUsers)
{
  myId = name + password;
  maxNumUsers = numUsers;
  myConnectedUsersIps.insert(init);
  version = 1; 
}

set<ClientEntry> Chatroom::getMyConnectedUsersIps()
{
  return myConnectedUsersIps;
}

bool Chatroom::addUser(const ClientEntry& user)
{
  version++; // increments version so associated threads know to update their list of connections
  return myConnectedUsersIps.insert(user).second;
}

bool Chatroom::removeUser(const ClientEntry& user)
{
  version++; // increments version so associated threads know to update their list of connections
  return myConnectedUsersIps.erase(user);
}

bool Chatroom::testAccess(const string& name, const string& password)
{
  return ( myId == ( name + password ) );
}

bool Chatroom::isEmpty()
{
  return myConnectedUsersIps.empty();
}

bool Chatroom::isFull()
{
  return ( maxNumUsers == myConnectedUsersIps.size() );
}
